/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pkdl.helpers;

import java.util.Comparator;

import com.pkdl.dto.BenhNhanDTO;
import com.pkdl.dto.DichVuDTO;
import com.pkdl.dto.ThuocDTO;

public class SorterByName implements Comparator {

	public int compare(Object a, Object b) {
		String name1 = "";
		String name2 = "";
		// Treat empty strains like nulls
		if (a instanceof BenhNhanDTO && b instanceof BenhNhanDTO) {
			String[] arr = ((BenhNhanDTO) a).getHoTen().split(" ");
			name1 = arr[arr.length - 1];
			arr = ((BenhNhanDTO) b).getHoTen().split(" ");
			name2 = arr[arr.length - 1];
		} else if (a instanceof DichVuDTO && b instanceof DichVuDTO) {
			name1 = ((DichVuDTO) a).getTenDichVu();
			name2 = ((DichVuDTO) b).getTenDichVu();
		} else if (a instanceof ThuocDTO && b instanceof ThuocDTO) {
			name1 = ((ThuocDTO) a).getTenThuoc();
			name2 = ((ThuocDTO) b).getTenThuoc();
		}

		return name1.toUpperCase().compareTo(name2.toUpperCase());
	}
}
